# main.py
import random
from fastapi import FastAPI,requests
from pydantic import BaseModel
import uvicorn

app = FastAPI(
    title="QuoteBot",
    description="随机一句中文鸡汤/毒鸡汤 API，供 Dify 调用",
    version="1.0.0"
)

# 极简语料，可自行扩充
quotes = [
    "你努力的样子，真的很美。",
    "别低头，皇冠会掉。",
    "今天不学习，明天变垃圾。",
    "你以为的极限，只是别人的起点。",
    "世上无难事，只要肯放弃。",
    "小时候笑是心情，长大后笑是表情。",
    "努力不一定成功，但不努力一定很轻松。",
    "生活不是等暴风雨过去，而是学会在雨中跳舞。",
]

class TextIn(BaseModel):
    type: str = "positive"   # positive / negative / random

class QuoteOut(BaseModel):
    quote: str

@app.post("/quote", response_model=QuoteOut)
def get_quote(payload: TextIn):
    if payload.type == "positive":
        pool = [q for q in quotes if "努力" in q or "美" in q or "跳舞" in q]
    elif payload.type == "negative":
        pool = [q for q in quotes if "垃圾" in q or "放弃" in q or "轻松" in q]
    else:
        pool = quotes
    quote = random.choice(pool) if pool else "今天也要元气满满鸭！"
    return QuoteOut(quote=quote)

@app.get("/")
def root():
    return {"status": "ok"}


if __name__ == "__main__":
    import uvicorn
    uvicorn.run("main:app", host="127.0.0.1", port=8000, reload=True)